{extend name="layout" /}
{block name="title"}{$__page_name__}列表{/block}


{block name="header_action"}
<!-- 添加按钮 -->
{if isset($addAction)}
{$addAction}
{/if}
{/block}

{block name="filter"}
{if isset($table)}
{$table->getFilter()}
{/if}
{/block}


{block name="body"}
{if isset($table)}
<style>
    #list {
        width: 1600px;
    }

    #list tbody tr td {
        max-width: 200px;
        overflow: hidden;
    }
</style>
{if isset($review)}
<div class="review layui-form">
    <button class="layui-btn">审核通过</button>
    <button class="layui-btn layui-bg-orange">审核驳回</button>
</div>
{/if}
<table class="layui-table" lay-skin="line" id="list">

    <!-- 表头 -->
    <thead>
    <tr>
        <th><label>
            <input type="checkbox" class="bar-checkbox">
        </label></th>
        {foreach $table->getHeader() as $label }
        <th>{$label}</th>
        {/foreach}

        <!-- 操作 -->
        {if $table->getActions() }
        <th>操作</th>
        {/if}
    </tr>
    </thead>

    <!-- 主体 -->
    {foreach $table as $index=>$row }
    <tbody>
    <tr data-id="{$row->getRowId()}">
        <td><label>
            <input type="checkbox" data-id="{$row->getRowId()}" class="list-checkbox">
        </label></td>
        {foreach $row as $rowIndex=>$td }
        <td class="align-middle text-sm text-gray-600">{$td}</td>
        {/foreach}

        <!-- 操作 -->
        {if $row->getActions() }
        <td>
            {$row->getActions()}
        </td>
        {/if}
    </tr>
    </tbody>
    {/foreach}
</table>

{/if}
{/block}

{block name="pagination"}

<!-- 空数据 -->
{if $table->getTotal()===0}
<div class="empty-data">
    <img src="{$static_root}img/no_data.png" alt="空数据">
    <span>列表为空</span>
</div>


{/if}

<!-- 分页 -->
{if isset($table)}
{$table->getPage()}
{/if}
{/block}
{block name="body_script"}
<script>
    const {log} = console;
    let idSet = new Set();
    let url = "{:url('reviewBatch')}"
    layui.use(["jquery", "form"], function () {
        const $ = layui.jquery;
        const form = layui.form;
        $(".bar-checkbox").change(function (el) {
            $(".list-checkbox").each(function () {
                let barBoxChecked = $(el.target).is(":checked");
                if (barBoxChecked) {
                    $(this).prop("checked", barBoxChecked);
                    idSet.add($(this).attr("data-id"));
                } else {
                    $(this).prop("checked", "");
                    idSet.clear();
                }
                let that = $(el.target);
                $(this).change(function (el) {
                    that.prop("checked", "");
                    if ($(this).is(":checked")) {
                        idSet.add($(this).attr("data-id"));
                    } else {
                        idSet.delete($(this).attr("data-id"));
                    }
                });
            });
        });
        $(".list-checkbox").each(function () {
            $(this).change(function (el) {
                if ($(this).is(":checked")) {
                    idSet.add($(this).attr("data-id"));
                } else {
                    idSet.delete($(this).attr("data-id"));
                }
            });
        });
        $(".review button").first().click(function(){
            $.get({
                url: url + "?ids=" + Array.from(idSet).join(",") +"&type={$typeY}",
                success(data) {
                    if (data.code) {
                        layer.msg('操作成功', {icon: 1});
                        window.location.reload();
                    } else {
                        layer.msg(data.msg, {icon: 2});
                    }
                }
            });
        });

        $(".review button").last().click(function(){
            $.get({
                url: url + "?ids=" + Array.from(idSet).join(",") +"&type={$typeN}",
                success(data) {
                    if (data.code) {
                        layer.msg('操作成功', {icon: 1});
                        window.location.reload();
                    } else {
                        layer.msg(data.msg, {icon: 2});
                    }
                }
            });
        });
    });
</script>
{/block}